public class Parentesis {

	static int arr[];

	

	public static int t(int i, int j) {
		if (i==j)
			return arr[i]==1?1:0;
		else {
			int res=0;
			for (int k = i; k < j; k+=2) {
				if (arr[k + 1] == 2)
					res+=t(i,k)*t(k+2,j);
				if (arr[k + 1] == 3)
					res+=(t(i,k)+f(i,k))*(t(k+2,j)+f(k+2,j))-f(i,k)*f(k+2,j);
				if (arr[k + 1] == 4 )
					res+=t(i,k)*f(k+2,j)+f(i,k)*t(k+2,j);
			}
			return res;
		}
	}
	
	public static int f(int i, int j){
		if (i==j)
			return arr[i]==0?1:0;
		else {
			int res=0;
			for (int k = i; k < j; k+=2) {
				if (arr[k + 1] == 2)
					res+=(f(i,k)+t(i,k))*(f(k+2,j)+t(k+2,j))-t(i,k)*t(k+2,j);
				if (arr[k + 1] == 3)
					res+=f(i,k)*f(k+2,j);
				if (arr[k + 1] == 4 )
					res+=(f(i,k)+t(i,k))*(f(k+2,j)+t(k+2,j)) -( t(i,k)*f(k+2,j)+f(i,k)*t(k+2,j));
			}
			return res;
		}
	}

	public static void main(String[] args) {
		//cadena de la forma true or false and true xor false
		//es igual a 1 3 0 2 1 4 0
		//true = 1
		//false = 0
		//and = 2
		//or = 3
		//xor = 4
		//arr=new int[]{1,2,0,4,1,3,0,4,1,2,0};
		arr=new int[]{1,2,0,4,1,3,0};
		
		int j=arr.length;
		System.out.println(t(0,j-1));

	}

}
